const sweetAlert = ( message = "Internal Server Error!", status = "error", attr = {}, callback ) => { let config = { html: message, icon: status, confirmButtonText: "Ya, lanjut!", cancelButtonText: "Tidak, batal", buttonsStyling: !1, customClass: { confirmButton: "btn fw-bold btn-primary", cancelButton: "btn fw-bold btn-active-light-primary", }, // target: ".modal-dialog", ...attr, }; Swal.fire(config).then((result) => { if (callback) { callback(result); } }); }; const setLoadingButton = (elementSelector = null, status = false) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } if (status) { selector.attr("disabled", false); selector.attr("data-kt-indicator", "off"); selector.find("i").removeClass("d-none"); } else { selector.attr("disabled", true); selector.attr("data-kt-indicator", "on"); selector.find("i").addClass("d-none"); } }; const resetFormError = (elementSelector) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } $.each(selector.find("[data-field]"), (index, element) => { selector .find(`[name='${element.getAttribute("data-field")}']`) .removeClass("is-invalid"); element.innerHTML = ""; }); }; const setFormError = (elementSelector, errors = []) => { let selector; let errorKey; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } const field = selector.find("[data-field]"); $.each(field, (index, element) => { errorKey = element.getAttribute("data-field"); if (errors[errorKey]) { selector.find(`#${errorKey}`).addClass("is-invalid"); element.innerHTML = errors[errorKey]; } else { selector.find(`#${errorKey}`).removeClass("is-invalid"); element.innerHTML = ""; } errorKey = ""; }); }; const resetForm = (elementSelector, callback) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } selector.trigger("reset"); selector.find(`.image-input`).removeClass("image-input-changed"); selector.find(`.image-input`).addClass("image-input-empty"); selector.find(`.image-input .image-input-wrapper`).css({ "background-image": "none", }); selector.find(` select, input, textarea`).each(function () { let attrType = $(this).attr("type"); if (attrType === "radio" || attrType === "checkbox") { $(this).prop("checked", false); } else { $(this).val("").trigger("change"); $(this).val(""); } if (callback) callback(); }); resetFormError(elementSelector); }; const setDaterange = ( elementSelector, start, end, format = "D-MM-YYYY", callback = undefined ) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } function cb(start, end, title) { selector .find("#date") .html(`${start.format(format)} - ${end.format(format)}`); selector.find("#title").html(title); selector .find("input") .val(`${start.format(format)} - ${end.format(format)}`); if (callback) callback(); } selector.daterangepicker( { startDate: start, endDate: end, ranges: { Today: [moment(), moment()], Yesterday: [moment().subtract(1, "days"), moment().subtract(1, "days")], "Last 7 Days": [moment().subtract(6, "days"), moment()], "Last 30 Days": [moment().subtract(29, "days"), moment()], "This Month": [moment().startOf("month"), moment().endOf("month")], "Last Month": [ moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month"), ], }, }, cb ); cb(start, end); }; const bootstrapTableConfig = () => { return { toolbar: "#toolbar", sidePagination: "server", queryParams: (params) => { $("[data-filter]").each(function () { params[$(this).attr("name")] = $(this).val(); }); return params; }, responseHandler: (res) => { res.rows = res?.rows.map((row, index) => { row.no = parseInt(res.from) + (index + 1); return row; }); return res; }, pagination: true, search: true, searchHighlight: true, singleSelect: false, striped: true, showColumns: false, showRefresh: false, showToggle: false, showFullscreen: false, showPaginationSwitch: false, pageSize: 5, pageList: [5, 10, 25, 50, "all"], iconSize: "sm", classes: "table align-middle table-row-dashed fs-6 gy-5 fw-semibold text-gray-600", buttonsClass: "primary btn-sm", loadingTemplate: () => `
Memuat data harap tunggu...
`, formatNoMatches: () => `Tidak ditemukan data yang cocok`, formatShowingRows: (pageFrom, pageTo, totalRows) => "", formatRecordsPerPage: (pageNumber) => pageNumber, headerStyle: function headerStyle(column) { let style = { classes: "text-gray-400 fw-bold fs-7 text-uppercase gs-0", }; return style; }, onColumnSwitch: function () { $("#btn_del_all").addClass("d-none"); KTMenu.createInstances(); KTApp.init(); }, onLoadSuccess: function (e) { // $('.fixed-table-pagination').find('.page-next a').html(``) // $('.fixed-table-pagination').find('.page-pre a').html(``) // $('.fixed-table-pagination').find(`.page-list a`).each((i, el) => { // if (`${this.pageSize}` === $(el).text()) { // $(el).addClass('active') // } // }); $("#btn_del_all").addClass("d-none"); KTMenu.createInstances(); KTApp.init(); }, onPageChange: (number, size) => { // $('.fixed-table-pagination').find('.page-list a.active').removeClass('active'); }, onCheckAll: (val, _el) => { val.length > 0 ? $("#btn_del_all").removeClass("d-none") : false; }, onUncheckAll: (_el, val) => { $("#btn_del_all").addClass("d-none"); }, onCheck: (val, el) => { $("#btn_del_all").removeClass("d-none"); }, onUncheck: (val, el) => { let selectedItem = $(el) .parents("table") .bootstrapTable("getSelections").length; selectedItem === 0 ? $("#btn_del_all").addClass("d-none") : false; }, }; }; const bootstrapTableCustomeToolbar = (elementSelector) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } $("#btn_fullscreen").click(function (e) { e.preventDefault(); selector.bootstrapTable("toggleFullscreen"); }); $("#btn_refresh").click(function (e) { e.preventDefault(); selector.bootstrapTable("refresh"); }); }; const showToast = (title, message, type = "success") => { let toastEl = $("#toast"); toastEl .find(".toast-icon") .removeClass(function (index, className) { return (className.match(/(^|\s)text-\S+/g) || []).join(" "); }) .addClass(`text-${type}`); toastEl.find(".toast-body").html(message); toastEl.find(".toast-title").html(title); bootstrap.Toast.getOrCreateInstance(toastEl[0]).show(); };